package com.cn.yz.springboot.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cn.yz.springboot.model.OpLog;
import com.cn.yz.springboot.service.OpLogService;

@RestController
public class TableSplitController {

	@Autowired
	private OpLogService opLogService;
	
	@RequestMapping("tableSplit/addOPLog/{bussinessId}/{operatorId}")
	public String addOpLog(@PathVariable int bussinessId,@PathVariable String operatorId){
		OpLog opLog = new OpLog();
		UUID uid = UUID.randomUUID();
		opLog.setId(uid.toString());
		opLog.setBussinessId(bussinessId);
		opLog.setOperatorId(operatorId);
		opLog.setOperatorTime(new Date());
		opLog.setOpYear("2016");
		if(opLogService.addOpLog(opLog)){
			return "新增成功";
		}
		return "新增失败";
	}
	
	@RequestMapping("tableSplit/getOpLogs/{opYear}")
	public Object getOpLogs(@PathVariable String opYear,@RequestParam(value="aa", required=false)String operatorId,@RequestParam(value="bb", required=false)String bussinessId){
		Map<String,Object> condition = new HashMap<String,Object>();
		if(operatorId!=null){
			condition.put("operatorId", operatorId);
		}
		if(bussinessId!=null){
			condition.put("bussinessId", bussinessId);
		}
		condition.put("opYear", opYear);
		return opLogService.findOpLogByCondition(condition);
	}

	@RequestMapping("tableSplit/getOpLogs/{opYear}/{id}")
	public Object getOpLogs(@PathVariable String opYear,@PathVariable String id){
		return opLogService.findOpLogById(id, opYear);
	}
}
